package com.spider.spiderorderbasedata.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spider.spiderorderbasedata.model.entity.DataLocation;
import com.spider.spiderorderbasedata.service.DataLocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author xiong.bo
 * @version 1.0
 * @date 2024/5/10 8:43 下午
 */

@Api(tags = "作业位置控制器")
@Slf4j
@RestController
@RequestMapping("/location")
public class DataLocationController {

    @Autowired
    private DataLocationService dataLocationService;

    @ApiOperation("作业位置列表")
    @GetMapping
    public ResponseEntity<IPage<DataLocation>> selectPage(@RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(dataLocationService.selectPage(page, pageSize));
    }

    @ApiOperation("查询作业位置详情")
    @GetMapping("/{id}")
    public ResponseEntity<DataLocation> findById(@PathVariable Long id) {
        return ResponseEntity.ok(dataLocationService.findById(id));
    }


    @ApiOperation("新增作业位置主表")
    @PostMapping
    public ResponseEntity<DataLocation> saveLocation(@RequestBody DataLocation dataLocation) {
        return ResponseEntity.ok(dataLocationService.saveLocation(dataLocation));
    }

    @ApiOperation("编辑作业位置主表")
    @PutMapping
    public ResponseEntity<DataLocation> editLocation(@RequestBody DataLocation dataLocation) {
        return ResponseEntity.ok(dataLocationService.editLocation(dataLocation));
    }

    @ApiOperation("删除某条作业位置主表")
    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteLocation(@PathVariable Long id) {
        return ResponseEntity.ok(dataLocationService.deleteLocation(id));
    }


}
